package com.baiytfp.hf.HFDataExchange.common.utils.auth;

import java.util.regex.Pattern;

public enum RuleMatchEnum {
	
	
	
	/**
	 *  密码正则
	 *  
	 * 	(?!^\\d+$)不能全是数字
	 *	(?!^[a-zA-Z]+$)不能全是字母
	 *	(?!^[_#@]+$)不能全是符号（这里只列出了部分符号，可自己增加，有的符号可能需要转义）
	 *	.{8,}长度不能少于8位
	 *	合起来就是
	 *	(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{8,}
	 *
	 * 
	 *  	  
	 */
	
	/*PWD_1("密码",
			"^([A-Z]|[a-z]|[0-9]|[`~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“'。，、？]){8,16}$",
			"密码为8-16位，且须含字母、数字，特殊字符【中文特殊字符亦可】" ),
	PWD_2("密码",
			"^(?!^[a-zA-z]+$)(?!^\\d+$)(?!^[!@#$%^&*]+$)(?!^[a-zA-z\\d]+$)(?!^[a-zA-z!@#$%^&*]+$)(?!^[\\d!@#$%^&*]+$)([a-zA-Z\\d!@#$%^&*]+$).{8,}$",
			"密码必须含字母、数字，特殊字符,且长度为8位以上"), */
	
	TEL("电话",new String[] {
			"^(\\d{3,4}-)?\\d{6,8}$"
			},""),
	FAX("传真",new String[] {
			"^[+]{0,1}(\\d){1,3}[  ]?([-]?((\\d)|[  ]){1,12})+$"
			},""),
	PHONE("手机",new String[] {
			"^[1]+[3,5]+\\d{9}$"
			},""),
	EMAIL("邮箱",new String[] {
			"^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"
			},""),
	IP("IP地址",new String[]{"^"
			+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
			+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
			+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
			+ "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$"},"255.255.255.0 "),
	URL_ABSOLUTE("URL",new String[] {
			"^(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]$"
			},"绝对路径"),
	URL_RELATIVE("URL",new String[] {
			"^[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]$"
			},"相对路径"),
	POSTCODE("",new String[] { "^\\d{6}$" },""),
	USER_CODE("用户名正则",new String[] {
			"^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$"
			},"只能输入5-20个以字母开头、可带数字、“_”、“.”的字串" );
	
	private String[] rule;
	private String name;
	private String desc;
	
	private RuleMatchEnum(String name, String[] rule,String desc) {
		this.name = name;
		this.rule = rule;
		this.desc = desc;
	}
	
	public String[] getRuleText() {
		return this.rule;
	}
	
	public String getRuleName() {
		return this.name;
	}
	
	public String getDesc() {
		return this.desc;
	}
	
	public boolean match( String str ) {
		Pattern pattern = null;
		boolean rs = true;
		for(String text : this.getRuleText()) {
			pattern = Pattern.compile(text);
			rs = rs && pattern.matcher(str).matches();
		}
		return rs;
	}
	
}
